lengthChance("org-keywords",20)
function placeShow(){
    //收缩效果
    function togglePlace(){
        $(".org-place ul").css("display","none");
        $(".org-place dd").css("display","none");
        $(".org-place").on("click","div", function(){
            // console.log($(this).next()[0])
            $(this).next().slideToggle(200)
        })
        $(".org-place>ul>li").on("click","ul", function(){
            // console.log($(this).next()[0])
            $(this).next().slideToggle(200);
        })
        $(".org-place>ul>li").on("click","dt",function(){
            $(this).siblings().slideToggle(200)
          })
    }
   
    //
    dataCall(areaInfo)
   function areaInfo(el){
    console.log(el)
        let area = el.filter(function(element){
            return element.administrativeLevel == "3"
        })
        $(area).each(function(index,nowEl){
            {
                $("#org-place").append($("<div><i><img src='../img/GISImg/toRight.png'></i>"+nowEl.administrativeName+"</div>"))
            }
        })
    
        $($("#org-place")).append($("<ul></ul>"))
        let town = el.filter(function(element){
            return element.administrativeLevel == "4"
        })
        let village = el.filter(function(element){
            return element.administrativeLevel == "5"
        })
        // console.log(town,village)
        $(town).each(function(index,nowEl){
            {
                
                let oli = $("<li ></li>")
                oli.append($("<dt><i><img src='../img/GISImg/toRight.png'></i>"+nowEl.administrativeName+"</dt>"));
                $(village).each(function(index2,nowEl2){

                         if(nowEl.administrativeName===nowEl2.parentName){
                        
                           oli.append($("<dd>"+nowEl2.administrativeName+"</dd>"))
                        }
                })
                $("#org-place ul").append(oli)
               
            }
        })
        $("#org-place").on("click","div,dd,dt",function(){
            let text = ($(this).text())
            $(el).each(function(index3,el3){
               
                if(el3.administrativeName == text){
                    $("#alter").removeAttr("disabled").css("cursor","pointer")
                    $(".table-right input").removeAttr("disabled")
                    $(".table-right select").removeAttr("disabled")
                    $(".table-right textarea").removeAttr("disabled")
                    $("#org-name").val(el3.administrativeName);
                    let option = $("<option selected>"+el3.parentName+"</option>")
                    $("#org-prevlevel").append(option).css("color","black").siblings(":selected").removeAttr("selected")
                    if(el3.administrativeLevel != "5"){
                        if(!$("#org-p")[0]){
                            let div = $("<p id='org-p'>当前机构编号存在下级关联,不可修改</p>")
                            $(div).css({
                                "fontSize":"14px",
                                "position":"relative",
                                "left":"120px",
                                "top":"-13px"
                            })
                            $("#org-num").attr("disabled",true);
                            $(".org-disChange").height("60px").append(div)
                        }else{
                            $("#org-num").attr("disabled",true);

                        }
                    }else{
                        $("#org-p").remove();
                        $(".org-disChange").height("40px")
                        
                    }
                   

                    $("#org-num").val(el3.administrativeCode);
 
                    inputColor()
                }
            })
           
        })
        togglePlace()
        $("#org-place").on("click","div,dt",function(){
            if($(this).children("i").children("img.turn")[0]){
                $(this).children("i").children("img").removeClass("turn")
            }else{
                $(this).children("i").children("img").addClass("turn")
            }
            

        })
   }

   function inputColor(){
       $(".table-right input").css("backgroundColor","white")
       $(".table-right select").css("backgroundColor","white")
       $(".table-right input:disabled").css("backgroundColor","#F5F7FA")
       $(".table-right select:disabled").css("backgroundColor","#F5F7FA")
      
   }
        inputColor()
}
placeShow()

function isVerifyOrg(){
    $("#org-name").on("blur",function(){
        isTrue("org-name","isEmpty","名称不能为空")
        window.onkeyup = function(){
            isTrue("org-name","isEmpty","名称不能为空")
        }  
    })
    $("#org-sName").on("blur",function(){
        isTrue("org-sName","isEmpty","简称不能为空")
        window.onkeyup = function(){
            isTrue("org-sName","isEmpty","简称不能为空")
        }  
    })
    $("#org-num").on("blur",function(){
        isTrue("org-num","isEmpty","编号不能为空")
        window.onkeyup = function(){
            isTrue("org-num","isEmpty","编号不能为空")
        }  
    })
    $("#org-linkman").on("blur",function(){
        isTrue("org-linkman","isEmpty","联系人不能为空");

        window.onkeyup = function(){
            isTrue("org-linkman","isEmpty","联系人不能为空");
        }  
    })
    $("#org-linknum").on("blur",function(){
        isTrue("org-linknum","isEmpty","电话不能为空");
        isTrue("org-linknum","isPhoneNum","电话号码不正确");
        window.onkeyup = function(){
            isTrue("org-linknum","isEmpty","电话不能为空");
            isTrue("org-linknum","isPhoneNum","电话号码不正确");
        }  
    })
    $("#org-address").on("blur",function(){
        isTrue("org-address","isEmpty","详细地址不能为空");

        window.onkeyup = function(){
            isTrue("org-address","isEmpty","详细地址不能为空");
        }  
    })
    $("#alter").on("click",function (){
        $("#org-name").blur()
        $("#org-sName").blur()
        $("#org-num").blur()
        $("#org-linkman").blur()
        $("#org-linknum").blur()
        $("#org-address").blur()
})
}
isVerifyOrg()